Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection status issue (#2519) #3364

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ann0see
Copy link
Member

@ann0see ann0see commented Sep 8, 2024

This is a manual port of #2550 by @pgScorpio

Short description of changes

First step to get to know the codebase of #2550

CHANGELOG: DO NOT MERGE

Context: Fixes an issue?

Fixes: #2519
Supersedes: #2550

Does this change need documentation? What needs to be documented and how?

No

Status of this Pull Request

Ready for first review and decision on how to move forward.

What is missing until this pull request can be merged?

Review.
It compiles but not every part of the code is fully understood and commented.

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 2 times, most recently from b12ce7e to 2b9d985 Compare September 8, 2024 09:58
@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 2 times, most recently from d6e5a6c to 38fb414 Compare September 8, 2024 10:28
@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

Coding style check also fails on main. Seems to be an unrelated issue?

@ann0see ann0see marked this pull request as draft September 8, 2024 10:34
@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

Pasting from previous PR here:

Moved Connect/Disconnect code from CClientdlg to CClient.
Now using the proper connected checks in several places.
Added bDisconnectAndDisable to CChannel. (For a Client now
Channel.Disconnect() will block audio data and auto disable the channel on disconnected)

src/client.cpp Outdated Show resolved Hide resolved
src/client.cpp Outdated Show resolved Hide resolved
@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 3 times, most recently from db402b9 to 10a4d61 Compare September 8, 2024 15:23
@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 10a4d61 to a5af8cc Compare September 8, 2024 15:25
src/main.cpp Show resolved Hide resolved
src/client.cpp Show resolved Hide resolved
@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 3 times, most recently from f7f0515 to 1614b81 Compare September 8, 2024 16:08
@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 1614b81 to 535f781 Compare September 8, 2024 16:13
@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

Ok.

a5af8cc is for having a smaller diff in this PR. The renaming of methods can happen in another PR.

Client.Start() and Client.Stop() have been re-introduced in 535f781, but can be - of course - merged again if wanted.

I think, this PR should now get an in depth review.

@@ -121,8 +120,11 @@ class CClient : public QObject

void Start();
void Stop();
bool Connect ( QString strServerAddress, QString strServerName );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make sense to introduce an easy to call Connect() and Disconnect() method IMO, so this is good.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these in client.cpp rather than clientdlg.cpp is important. It's important enough to be done in a single PR on its own. I think we should start with that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. That's issue #3367

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factored out into #3372

bool IsRunning() { return Sound.IsRunning(); }
bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); }
bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); } // For OnTimerCheckAudioDeviceOk only
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted naming. May need some in depth review and discussion.

@@ -427,8 +429,9 @@ protected slots:

void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );

void Connecting ( QString strServerName );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a missing slot.

src/client.h Outdated
void Disconnected();
void SoundDeviceChanged ( QString strError );
void SoundDeviceChanged();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about removing the error message handling. Could be reverted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above:

  • split this out to a separate PR
  • have two slots, one for GUI, one for headless, and pass the error to each


// initiate connection
Connect ( strSelectedAddress, strMixerBoardLabel );
// TODO: investigate and add error handling on failed Connect() call.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO as commented in code.

@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

I think it should only do changes on the client side.
The PR is still huge and potentially we need to extract the most important points. See the linked PR for old discussions.
My goal is to use this to lay foundations for the JSON-RPC connect/disconnect calls.

@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

So we need to try understanding what gets changed.

src/channel.cpp Outdated Show resolved Hide resolved
src/channel.cpp Outdated Show resolved Hide resolved
src/channel.h Outdated
@@ -76,7 +76,7 @@ class CChannel : public QObject

void PrepAndSendPacket ( CHighPrioSocket* pSocket, const CVector<uint8_t>& vecbyNPacket, const int iNPacketLen );

void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
void ResetTimeOutCounter() { iConTimeOut = bDisconnectAndDisable ? 1 : iConTimeOutStartVal; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. Should probably be expanded into an assignment and boolean comparison.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I not enthused by the whole bDisconnectAndDisable -- I can't see the problem it's trying to fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they wanted to introduce an intermediate state somehow to fix the button being able to get out of sync.
From #2550 (comment)

Added bDisconnectAndDisable to CChannel. (For a Client now
Channel.Disconnect() will block audio data and auto disable the channel on disconnected)

@ann0see
Copy link
Member Author

ann0see commented Sep 8, 2024

Maybe we can reconstruct something from pgScorpio@648880c

@@ -1193,65 +1167,36 @@ void CClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int
ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr, iPingTime, iNumClients );
}

void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& strMixerBoardLabel )
void CClientDlg::OnConnect ( QString strServerName )
Copy link
Member Author

@ann0see ann0see Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pljones Potentially we only need this (see signal connection above) for the JSON-RPC PR.

@softins
Copy link
Member

softins commented Sep 13, 2024

I looked quickly through the changes the other day and didn't notice anything of concern, but I haven't yet had time to study in detail.

@ann0see
Copy link
Member Author

ann0see commented Sep 13, 2024

I believe there's a need to check if the changed conditions in the if statements are really correct or if the bug lays elsewhere

}
else
{
// For disconnected clients set defaults
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this done when the disconnect actually happens, rather than here? Like in line 645? Is this just duplicated? Or is there a reason for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a reason for it.
It's probably trying to ensure that bDisconnectAndDisable is representing the client being in process of disconnecting?

Copy link
Collaborator

@pljones pljones Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what job it's doing that setting iConTimeOut to 1 doesn't already do. It still needs iConTimeOut set to 1, too, so it just adds complexity rather than removing it, without improving readability either.


if ( bDisconnectAndDisable && !bIsServer )
{
bDisconnectAndDisable = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??! So these get set to the same values whether eGetStatus is GS_CHAN_NOW_DISCONNECTED or GS_CHAN_NOT_CONNECTED? Now I'm really confused.

src/channel.h Outdated
@@ -76,7 +76,7 @@ class CChannel : public QObject

void PrepAndSendPacket ( CHighPrioSocket* pSocket, const CVector<uint8_t>& vecbyNPacket, const int iNPacketLen );

void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
void ResetTimeOutCounter() { iConTimeOut = (bDisconnectAndDisable && !bIsServer) ? 1 : iConTimeOutStartVal; }
Copy link
Collaborator

@pljones pljones Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what CChannel::Disconnect() is doing? Why is this change here?

The lifecycle of iConTimeOut should be pretty clear:

  • On client start, it should get initialised to 0, really.
  • On connect, and each time an audio packet is processed whilst connected, it should get set to iConTimeOutStartVal, which should be a multiple of iAudioFrameSizeSamples.
  • Each time no audio packet is received iAudioFrameSizeSamples will get deducted without a reset until such time time runs out and the client disconnects.
  • On manual disconnect, it should get set to 1, which is less than iAudioFrameSizeSamples, which means on the next time around, the client will disconnect as above.
  • Once disconnected, it will get set back to 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On manual disconnect, it should get set to 1, which is less than iAudioFrameSizeSamples, which means on the next time around, the client will disconnect as above.

Which I believe may not happen? Probably the fix is not here though.

@@ -337,7 +329,7 @@ void CClient::CreateServerJitterBufferMessage()
void CClient::OnCLPingReceived ( CHostAddress InetAddr, int iMs )
{
// make sure we are running and the server address is correct
if ( IsRunning() && ( InetAddr == Channel.GetAddress() ) )
if ( Channel.IsEnabled() && ( InetAddr == Channel.GetAddress() ) )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't about the channel being enabled. It's about whether the client is running. It's a different intent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the initial PR confused active channel and active client: #2550 (comment)

This difference needs documentation. IMO: Add (like for JSON-RPC) respective technical documentation before the respective methods. As end goal: Write them for every function, for now: Write docs while changing.

src/client.cpp Outdated Show resolved Hide resolved
src/client.cpp Outdated Show resolved Hide resolved
src/client.cpp Outdated Show resolved Hide resolved
Sound.Stop();
// start disconnection
// Channel.Disconnect() should automatically disable Channel as soon as disconnected.
// Note that this only works if sound is active!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why make the changes here?

Copy link
Member Author

@ann0see ann0see Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's mainly moving around the Channel.Disconnect() and Sound.Stop() code around.

This may be the actual bug fix?

}
}

void CClientDlg::Disconnect()
void CClientDlg::OnDisconnect()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidying up the mixer board should go in here, I guess.

@ann0see
Copy link
Member Author

ann0see commented Sep 13, 2024

Thanks for the review! I'll go through what I can answer later.

src/clientsettingsdlg.cpp Outdated Show resolved Hide resolved
@@ -963,6 +961,12 @@ int main ( int argc, char** argv )
// show dialog
ClientDlg.show();

// Connect on startup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be in main.cpp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's up to discussion. I do understand that one could put this functionality here. How it's handled currently also seems somewhat messy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is messy. But that's a bigger issue with how start up works.

@ann0see ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 2633d3c to 66edab5 Compare September 13, 2024 19:33
// disconnect the old server first
if ( pClient->IsRunning() )
// initiate connection
if ( pClient->Connect ( strSelectedAddress, strMixerBoardLabel ) )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored imo. Feels very clumsy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI should simply pass any captured details to Client and await feedback. There shouldn't be any testing of the response. (Any input validation should be factored out of Client if it needs sharing between Client and ClientDlg.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on Team
Development

Successfully merging this pull request may close these issues.

Connection status client and gui can get out of sync.
4 participants